<script>
import {getEditText, getText} from "@/utils/class/Pluponform";

export default {
  name: "textsetPage",
  data() {
    return {
      tableData: [],
      title: '',
      content: '',
      textQuery: {
        pageSize: '10',
        pageNum: '1',
      },
      dialogVisible: false,
      textQueryf: {
        code: 200,
        id: '',
        title: '',
        status: '',
        content: ''
      }
    }

  },
  methods: {
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => {
        });
    },

    //编辑
    handleClick(row) {
      // console.log(row);
      this.dialogVisible = true
      this.textQueryf.id = row.id
      this.title = row.title
      this.content = row.content

    },
    //编辑完保存
    sure() {
      this.dialogVisible = false
      this.textQueryf.content = this.content
      this.textQueryf.title = this.title
      getEditText(this.textQueryf).then(res => {
        //  console.log(res)
        this.$message.success('编辑成功')
        getText(this.textQuery).then(res => {
          // console.log(res)
          this.tableData = res.rows
        })
      })
    }
  },
  created() {
    getText(this.textQuery).then(res => {
      // console.log(res)
      this.tableData = res.rows
    })
  }
}
</script>

<template>
  <div>
    <div style="padding: 30px">
      <el-table
        :data="tableData"
        border
        style="width: 100%">
        <el-table-column
          label="序号"
          type="index"
          width="180">
        </el-table-column>
        <el-table-column
          label="名称"
          prop="title">
        </el-table-column>
        <el-table-column
          label="更新时间"
          prop="updateTime"
          width="200"
        >
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="200">
          <template slot-scope="scope">
            <el-button size="small" type="text" @click="handleClick(scope.row)">编辑</el-button>

          </template>
        </el-table-column>
      </el-table>
    </div>
    <!--    编辑富文本-->
    <div>
      <el-dialog
        :before-close="handleClose"
        :visible.sync="dialogVisible"
        style="text-align: center;height: 500px"
        width="60%">
        <div class="title">
          <input v-model="title" type="text">
        </div>
        <div class="text">
          <Editor v-model="content"/>
        </div>

        <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="sure">确 定</el-button>
  </span>
      </el-dialog>

    </div>
  </div>
</template>

<style lang="scss" scoped>
::v-deep.el-table th.el-table__cell.is-leaf, .el-table td.el-table__cell {
  text-align: center;
}

::v-deep.el-table--enable-row-transition .el-table__body td.el-table__cell {
  text-align: center;
}

::v-deep.ql-toolbar.ql-snow {
  text-align: left;
}

.title {
  width: 100%;
  text-align: center;
  margin: 0 auto 30px auto;
  color: #707070;

  input {
    border: none;
    text-align: center;
    font-size: 30px;
  }
}


//::v-deep.ql-toolbar.ql-snow + .ql-container.ql-snow {
//  //height: 300px;
//  overflow: scroll;
//}
</style>
